<!DOCTYPE html>
<html lang='en'>
<head>
	<meta charset='utf-8' />
	<meta name='renderer' content='webkit' />
	<meta name='viewport' content='width=device-width,user-scalable=no,initial-scale=1.0,shrink-to-fit=no,minimum-scale=1.0,maximum-scale=1.0,minimal-ui,viewport-fit=cover'/>
	<title>test</title>
</head>
<body>
	<script>
	//获取媒体设备
	navigator.mediaDevices.getUserMedia({audio:true, video:true}).then( stream => {
		//建立点对点连接
		let peerConnection = new RTCPeerConnection({
			iceServers: [{urls: 'stun:stun.l.google.com:19302'}]
		})
		peerConnection.addStream(stream)
		//绑定事件监听
		peerConnection.onaddstream = event => {
			console.log('receive remote stream:', event.stream)
		}
		//创建数据通道
		let dataChannel = peerConnection.createDataChannel('mychannel')
		dataChannel.onopen = () => {
			
		}
		dataChannel.onmessage = event => {
			console.log('received message:', event.data)
		}
	}).catch(error =>{
		console.log('getUserMedia failed:', error)
	})
	</script>
</body>
</html>